package common;

import dao.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘柄华
 * Date: 2022-06-08
 * Time: 18:38
 */
public class Util {
    public static User checkLoginStatus(HttpServletRequest req){
        // 此处判定当前是否处于登录状态~.
        // 如果能够拿到 Session, 并且拿到 Session 里的 user 对象, 就认为是已经登录过的状态
        HttpSession session = req.getSession(false);
        if(session == null){
            // 未登录的状态
            return null;
        }
        User user = (User) session.getAttribute("user");
        if(user == null){
            // 未登录的状态
            return null;
        }
        return user;
    }
}
